import React,{useEffect} from "react";
import {useParams,useLocation,useNavigate} from 'react-router-dom'
const Detail = () => {
    let id = null;
    const navigate = useNavigate();
    let paramsObj = useParams();
    if(paramsObj?.id) {
        id = paramsObj.id
    } else {
        let seachObj = new URLSearchParams(useLocation().search);
        console.log(seachObj.get(id))
        if(seachObj.get('id')) {
        id = seachObj.id;
        }
    }
    console.log(id,'-----')
    useEffect( () => {
        if (!id) {
            navigate('/')
        }
    },[])
   
    console.log(id);
    // path 动态参数部分
    // const { id }  = useParams();
    // console.log(id)
    // console.log(windwow.location.search)()
    // let paramsObj = new URLSearchParams(useLocation().search)
    // console.log(paramsObj.get('id'))
    console.log(useLocation())
    return (
        <>
        Detail{ id }
        </>
    )
}
export default Detail